import { getAppVoByIdUsingGet } from '@/services/backend/appController';
import '@umijs/max';
import { Button , Modal } from 'antd';
import React, { useEffect, useState } from 'react';

interface Props {
    visible: boolean;
    appId: number;
    onCancel: () => void;
}

/**
 * 创建弹窗
 * @param props
 * @constructor
 */
const DetailModal: React.FC<Props> = (props) => {
    const { visible, appId, onCancel } = props;

    const [appDetail, setAppDetail] = useState<API.AppVO>();
    useEffect(() => {
        if (appId < 0) {
            return;
        }
        getAppVoByIdUsingGet({
            id: appId,
        }).then((res) => {
            setAppDetail(res.data);
        })
    }, [appId])

    const openQuestion = () => {
        window.open(`/question/answer?appId=${appId}`);
    }
    return (
        <Modal
            destroyOnClose
            title={'应用详情'}
            open={visible}
            footer={null}
            onCancel={() => {
                onCancel?.();
            }}
        >
            <div>{appId}</div>
            <div>{appDetail?.appName}</div>
            <div>{appDetail?.appDesc}</div>
            <div>{appDetail?.appType}</div>
            <div>{appDetail?.createTime}</div>
            <div>{appDetail?.updateTime}</div>
            <div>{appDetail?.appType}</div>
            <div style={{ display: 'flex', justifyContent: 'center' }}>
                <Button type="primary" block onClick={openQuestion}>进行答题</Button>
            </div>

        </Modal>
    );
};
export default DetailModal;
